package com.mz.ozy.widget.dialog;

import android.app.Activity;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.mz.ozy.R;


/**
 * Created by administrator on 2019/3/14.
 */
public class AlertDialog extends BaseDialog implements View.OnClickListener {
    TextView tvContent;
    TextView tvTitle;

    private String title;
    private String tipContet;

    public AlertDialog(Activity mContext) {
        super(mContext, R.layout.dialog_common_alert, Gravity.CENTER, true);
        init();
    }

    public AlertDialog(Activity mContext, String title, String content) {
        super(mContext, R.layout.dialog_common_alert, Gravity.CENTER, true);
        this.title = title;
        this.tipContet = content;
        init();
    }


    private void init() {

        tvContent = getView(R.id.tv_content);
        tvTitle = getView(R.id.tv_title);
        getView(R.id.bnt_cancle).setOnClickListener(this);
        getView(R.id.bnt_confirm).setOnClickListener(this);

        if (!TextUtils.isEmpty(tipContet)) {
            tvTitle.setText(title);
            tvContent.setText(tipContet);
        }


    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bnt_confirm:
                if (mListener != null) {
                    mListener.onConfirm();
                }
                toggleDialog();
                break;
            case R.id.bnt_cancle:
                toggleDialog();
                break;
        }
    }

    private onDialogListener mListener;

    public void setOnDialogListener(onDialogListener listener) {
        mListener = listener;
    }

    public interface onDialogListener {
        void onConfirm();
    }

}
